/**
 * @file      ac_tlm_vid.h
 * @author    Bruno de Carvalho Albertini
 * 
 * @author    The ArchC Team
 *            http://www.archc.org/
 *
 *            Computer Systems Laboratory (LSC)
 *            IC-UNICAMP
 *            http://www.lsc.ic.unicamp.br/
 * 
 * @version   0.1
 * @date      Sun, 02 Apr 2006 08:07:46 -0200
 * 
 * @brief     Defines a ac_tlm video screen.
 * 
 * @attention Copyright (C) 2002-2005 --- The ArchC Team
 * 
 *   This library is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Lesser General Public
 *   License as published by the Free Software Foundation; either
 *   version 2.1 of the License, or (at your option) any later version.
 * 
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   Lesser General Public License for more details.
 * 
 * 
 */

//////////////////////////////////////////////////////////////////////////////

#ifndef AC_TLM_VID_H_
#define AC_TLM_VID_H_

//////////////////////////////////////////////////////////////////////////////

// Standard includes
// SystemC includes
#include <systemc>
#include <stdio.h> // ANALIZAR NECESSIDADE DESSES 2 INCLUDES *******************************
#include <iostream>
// ArchC includes
#include "ac_tlm_protocol.H"
#include "SDL/SDL.h" //sera usado na impressao em tela
#include "SDL/SDL_ttf.h" //sera usado na impressao de caracteres em tela
//////////////////////////////////////////////////////////////////////////////

#define VID_BUFFER 1000 // VER ESSE NUM
#define VID_WIDTH  640
#define VID_HEIGHT 480
//////////////////////////////////////////////////////////////////////////////

// using statements
using tlm::tlm_transport_if;

//////////////////////////////////////////////////////////////////////////////

/// Namespace to isolate memory from ArchC
namespace user
{

  class ac_tlm_vid :
    public sc_module,
    public ac_tlm_transport_if // Using ArchC TLM protocol
  {
    public:

      /// Exposed port with ArchC interface
      sc_export< ac_tlm_transport_if > target_export;
      /// Internal write
      ac_tlm_rsp_status writev( const uint32_t & , const uint32_t & );
      /// Internal read
      //ac_tlm_rsp_status readv( const uint32_t & , uint32_t & );
      void desenhaPixel(int x, int y, const uint32_t &);
      void desenhaImagem(const char *arq, int x, int y);

      /**
       * Implementation of TLM transport method that
       * handle packets of the protocol doing apropriate actions.
       * This method must be implemented (required by SystemC TLM).
       * @param request is a received request packet
       * @return A response packet to be send
       */
      ac_tlm_rsp transport( const ac_tlm_req &request ) {

        ac_tlm_rsp response;

        switch( request.type ) {
          case WRITE :     // Packet is a WRITE one
            response.status = writev( request.addr , request.data );
            break; 
          default :
            response.status = ERROR;
            break; 
        }

        return response;
      }


      /** 
       * Default constructor.
       * 
       * @param k Memory size in kilowords.
       * 
       */
      ac_tlm_vid( sc_module_name module_name , int k = 1000000 ); // ver esse K

      /** 
       * Default destructor.
       */
      ~ac_tlm_vid();

      void atualiza();
    private:
      SDL_Surface *tela; // A tela propriamente dita
      TTF_Font *fonte; // fonte
  };

};

#endif //AC_TLM_VID_H_
